package main;

import java.util.ArrayList;
import java.util.List;

public class Abonement {
    private String status;
    private String name;
    private String adress;
    private String phoneNumber;
    private int limit; // max 3 books at one time

    public String getName() {
        return name;
    }

    private List<Book> currentBooks = new ArrayList<Book>();

    public Abonement(String name, String adress, String phoneNumber) {
        this.name = name;
        this.adress = adress;
        this.phoneNumber = phoneNumber;
        this.limit = 3;
    }

    public void addBook(Book book) throws LibraryException {
        if (!checkForLimit()) {
            throw new LibraryException("Book limit Exceed");
        }
        currentBooks.add(book);
        limit--;
    }

    private boolean checkForLimit() {
        return limit > 0;
    }


    public void setLimit(int limit) {
        this.limit = limit;
    }


    public void setStatus(String status) {
        this.status = status;
    }

    public List<Book> getCurrentBooks() {
        return currentBooks;
    }

    @Override
    public boolean equals(Object object) {
        if (object instanceof Abonement) {
            Abonement abonement = (Abonement) object;
            return name.equals(abonement.name) && adress.equals(abonement.adress)
                    && phoneNumber.equals(abonement.phoneNumber);
        } else {
            return false;
        }
    }

    @Override
    public String toString() {
        return String.format("%s %s %s %s", name, adress, phoneNumber, limit);
    }
}
